/* win32.h
 *
 */
#define _WIN32_WINNT 0x501

#ifndef WIN32_H
#define WIN32_H

#ifndef SIGHUP
#define SIGHUP 1
#endif
#ifndef SIGINT
#define SIGINT 2
#endif
#ifndef SIGUSR1
#define SIGUSR1 10
#endif
#ifndef SIGUSR2
#define SIGUSR2 12
#endif
#ifndef SIGTERM
#define SIGTERM 15
#endif

#include <Winsock2.h>
#include <ws2tcpip.h>
#include <errno.h>

#pragma warning(disable : 4996)

#if defined(_MSC_VER)
// for MSVC 6.0
typedef          __int64    int64_t;
typedef unsigned __int64   uint64_t;
typedef          int        int32_t;
typedef unsigned int       uint32_t;
typedef          short      int16_t;
typedef unsigned short     uint16_t;
typedef          char        int8_t;
typedef unsigned char       uint8_t;
#define inline __inline
#endif // _WIN32 && _MSC_VER

#define pid_t int
#define EWOULDBLOCK        EAGAIN
#define EAFNOSUPPORT       47
typedef int socklen_t;

#define O_BLOCK 0
#define O_NONBLOCK 1
#define F_GETFL 3
#define F_SETFL 4

#define IOV_MAX 1024
struct iovec {
	u_long iov_len;  
	char FAR* iov_base;
};
struct msghdr
{
	void	*msg_name;			/* Socket name			*/
	int		 msg_namelen;		/* Length of name		*/
	struct iovec *msg_iov;		/* Data blocks			*/
	int		 msg_iovlen;		/* Number of blocks		*/
	void	*msg_accrights;		/* Per protocol magic (eg BSD file descriptor passing) */ 
	int		 msg_accrightslen;	/* Length of rights list */
};

int fcntl(SOCKET s, int cmd, int val);
int inet_aton(register const char *cp, struct in_addr *addr);

#define close(s) closesocket(s)
#define write(a, b, c) send(a, b, c, 0) 
//size_t write(int s, void *buf, size_t len); 
#define read(a, b, c) recv(a, b, c, 0)  
//size_t read(int s, void *buf, size_t len);

int inet_pton(int af, register const char *cp, struct in_addr *addr);
int sendmsg(int s, const struct msghdr *msg, int flags);

#undef errno
#define errno werrno()

int werrno();

int __cdecl _set_errno(int value);

#endif
